package com.shtel.paas.monitorcenter.system.management.user.management.controller;

import java.util.ArrayList;
import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestParam;

import com.shtel.paas.monitorcenter.system.management.user.management.entity.InsertEntity;

import com.shtel.paas.monitorcenter.system.management.user.management.entity.SearchEntity;
import com.shtel.paas.monitorcenter.system.management.user.management.entity.UpdateEntity;
import com.shtel.paas.monitorcenter.system.management.user.management.entity.deleteEntity;
import com.shtel.paas.monitorcenter.system.management.user.management.service.RoleAndAuthorityManagementService;
import com.shtel.paas.monitorcenter.system.management.user.management.service.UerManagementService;
import com.shtel.paas.monitorcenter.system.management.user.management.vo.MonitoringCenterUserVo;
import com.shtel.paas.monitorcenter.util.Page;
//import com.shtel.paas.sdk.core.RefreshableRestController;
//import com.shtel.paas.sdk.core.mybatis.EnablePaasMybatis;

/**
 * 
 * @author zhaochuan.zhong
 *
 */
import org.springframework.web.bind.annotation.RestController;//@EnablePaasMybatis

@MapperScan("com.shtel.paas.monitorcenter.system.management.user.management.mapper")
@RestController
public class UserManagementController {

	@Autowired
	private UerManagementService uerManagementService;

	@Autowired
	private RoleAndAuthorityManagementService roleAndAuthorityManagementService;

	/**
	 * 用户信息列表数据获取
	 */
	@GetMapping("/selectUserInfo")
	public Page<MonitoringCenterUserVo> getUserInfo(
			@RequestParam("userNo") String userNo,
			@RequestParam("userName") String userName,
			@RequestParam("belongToReglon") String belongToReglon,
			@RequestParam("belongToDepartment") String belongToDepartment,
			@RequestParam("AccountValidityPeriod") String AccountValidityPeriod,
			@RequestParam("gender") String gender,
			@RequestParam("emai") String emai,
			@RequestParam("telephone") String telephone,
			@RequestParam("page") Integer page,
			@RequestParam("pageSize") Integer pageSize) {
		SearchEntity rmpEnt = new SearchEntity();
		rmpEnt.setUserNo(userNo);
		rmpEnt.setUserName(userName);
		rmpEnt.setBelongToDepartment(belongToDepartment);
		rmpEnt.setBelongToReglon(belongToReglon);
		rmpEnt.setGender(gender);
		rmpEnt.setAccountValidityPeriod(AccountValidityPeriod);
		rmpEnt.setPage(page);
		rmpEnt.setSize(pageSize);
		Page<MonitoringCenterUserVo> pageContent = uerManagementService
				.selectUserInfo(rmpEnt);
		return pageContent;
	}

	/**
	 * 用户单个删除
	 */
	@GetMapping("/deleteByIdsAndUserNo")
	public Integer deleteByIdsAndUserNo(@RequestParam("del_ids") String del_ids) {
		deleteEntity rmpEnt = new deleteEntity();
		rmpEnt.setUserNo(del_ids);
		Integer String = uerManagementService.deleteByIdsAndUserNo(rmpEnt);
		return String;
	}

	/**
	 * 用户批量删除
	 */
	@GetMapping("/deleteBatch")
	public Integer deleteBatch(@RequestParam("del_ids") String del_ids) {
		List<String> emp = new ArrayList<>();

		// 参数调整
		if (del_ids.contains(",")) {
			String[] ids = del_ids.split(",");
			for (int i = 0; i < ids.length; i++) {
				if (ids[i] != null || ids[i] != "") {
					emp.add(ids[i]);
				}
			}
		}
		Integer result = uerManagementService.deleteBatch(emp);
		return result;
	}

	/**
	 * 用户信息列表数据插入
	 */
	@GetMapping("/insertUserInfo")
	public Integer insertUserInfo(
			@RequestParam("userNo") String userNo,
			@RequestParam("userName") String userName,
			@RequestParam("belongToReglon") String belongToReglon,
			@RequestParam("belongToDepartment") String belongToDepartment,
			@RequestParam("AccountValidityPeriod") String AccountValidityPeriod,
			@RequestParam("gender") String gender,
			@RequestParam("emai") String emai,
			@RequestParam("telephone") String telephone,
			@RequestParam("userPasswd") String userPasswd,
			@RequestParam("adminId") String adminId,
			@RequestParam("roleId") String roleId) {
		InsertEntity rmpEnt = new InsertEntity();
		rmpEnt.setUserNo(userNo);
		rmpEnt.setUserName(userName);
		rmpEnt.setBelongToDepartment(belongToDepartment);
		rmpEnt.setBelongToReglon(belongToReglon);
		rmpEnt.setEmai(emai);
		rmpEnt.setGender(gender);
		rmpEnt.setTelephone(telephone);
		rmpEnt.setAccountValidityPeriod(AccountValidityPeriod);
		rmpEnt.setUserPasswd(userPasswd);
		rmpEnt.setAdminId("3923dfbc-f025-4399-9f9a-e3708980b174");
		rmpEnt.setRoleId(roleId);
		Integer result = uerManagementService.insertUserInfo(rmpEnt);
		return result;
	}

	/**
	 * 用户信息列表数据更新
	 */
	@GetMapping("/updateUserInfo")
	public Integer updateUserInfo(
			@RequestParam("Id") String Id,
			@RequestParam("userNo") String userNo,
			@RequestParam("userName") String userName,
			@RequestParam("userPasswd") String userPasswd,
			@RequestParam("belongToReglon") String belongToReglon,
			@RequestParam("belongToDepartment") String belongToDepartment,
			@RequestParam("AccountValidityPeriod") String AccountValidityPeriod,
			@RequestParam("gender") String gender,
			@RequestParam("telephone") String telephone,
			@RequestParam("emai") String emai,
			@RequestParam("roleId") String roleId) {
		UpdateEntity rmpEnt = new UpdateEntity();
		rmpEnt.setId(Id);
		rmpEnt.setUserNo(userNo);
		rmpEnt.setUserName(userName);
		rmpEnt.setBelongToDepartment(belongToDepartment);
		rmpEnt.setBelongToReglon(belongToReglon);
		rmpEnt.setAccountValidityPeriod(AccountValidityPeriod);
		rmpEnt.setEmai(emai);
		rmpEnt.setTelephone(telephone);
		rmpEnt.setGender(gender);
		rmpEnt.setUserPasswd(userPasswd);
		rmpEnt.setRoleId(roleId);
		Integer result = uerManagementService.updateUserInfo(rmpEnt);
		return result;
	}

	/**
	 * 查询所有角色操作
	 * 
	 * @param
	 * @return result
	 * @create zhangyy 2018.05.23 查询列表无分页
	 */
	@GetMapping("/getRoleList")
	public Object getRoleList() {

		return roleAndAuthorityManagementService.getRoleList();

	}

}
